# coding=utf-8

import requests
from bs4 import BeautifulSoup
import pandas as pd


pd.set_option('display.max_rows', None)


def get_url(ts_code):  # 根据期数创建url
    # eastmoeny
    url = "http://quote.eastmoney.com/" + ts_code.strip() + ".html"
    return url

def get_zjlx_url(ts_code):
    # ts_code = ts_code[2:]
    url = "http://finance.sina.com.cn/realstock/company/"+ts_code.strip()+"/nc.shtml"
    # url = "http://data.eastmoney.com/zjlx/" + ts_code.strip() + ".html"
    return url


def _get_html(urls):
    response = requests.get(urls)
    # print(response.text)
    if response.status_code == 200:  # 有数据则返回的为200
        code = response.encoding
        str = response.text
        str = str.encode(code)
        str = str.decode('GBK')
        return str

    else:
        print('无数据！')
    return None


def get_chart_moneyflow_from_eastmoney(ts_code):
    url = get_url(ts_code)
    html = _get_html(url)
    bf = BeautifulSoup(html, "html.parser")
    # eastmoney
    # s = bf.find_all("div",{'class':"w330 fl mt10"})
    chart_money = bf.find_all("iframe", id='iframebingtu')  #返回资金流图

    # url_zjlx = get_zjlx_url(ts_code)
    # html_zjlx = _get_html(url_zjlx)
    #
    # # print(html_zjlx)
    # bf_zjlx = BeautifulSoup(html_zjlx, "html.parser")
    # # main_in = bf_zjlx.find("span", id="data_jlr").get_text()
    # # main_out = bf_zjlx.find("span", id="data_jzb").get_text()
    # # print(main_in + '  and  ' + main_out  )
    # b = bf_zjlx.find("div", id="MRFlow")
    # print(b)
    return chart_money
